<?php

declare(strict_types=1);

namespace App\Helpers;

use App\Event\HangupCallEvent;
use App\Event\HangupVideoEvent;
use Psr\EventDispatcher\EventDispatcherInterface;

/**
 * 事件分发类
 */
class EventUtil
{
    /**
     * 挂断通话事件
     */
    static function dispatchHangup($callRecord = null, $type = 'video')
    {
        if (!$callRecord) return false;
        $eventCls = $type == 'video' ? HangupVideoEvent::class : HangupCallEvent::class;
        return make(EventDispatcherInterface::class)->dispatch(new $eventCls(
            $callRecord->user_id,
            $callRecord->chat_user_id,
            $callRecord->call_time,
            $callRecord->from,
            $callRecord->call_mark,
        ));
    }
}
